<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/ui.all.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
		<script src="assets/scripts/ui/ui.dialog.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<script type="text/javascript" src="./assets/scripts/editor.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript" src="./assets/scripts//table.js"></script>
		<script type="text/javascript" src="./assets/scripts/search.js"></script>
		<style type="text/css">
input,
.text,
textarea {
	*font-family: "MS Pゴシック","ＭＳ Ｐゴシック","MS P Gothic";
	line-height:120%;
	height:25px;
	width:90%;
}
th span{width:100px;
		overflow:hidden;
		text-overflow:ellipsis;};
input.btnleft{	text-align:	left;};
.disp{border:0px;border-style:none;background-color:#99CCFF;}

table.formTable tr {height:38px;}
td  {height:38px;}
.errmsg{color:red;width:100%;};
.all_div {
  width:100%;
  float: left;  /* 左方向にフロート */
  position:relative;
}
/* 左カラム固定・右カラム可変 */
.l_div {
  width:29.99%;
  float: left;  /* 左方向にフロート */
}
.r_div {
float: right;  /* 左方向にフロート */
  width:70%;
  z-index:300;
  overflow-x:auto;
  overflow-y:hidden;
}
 </style>
		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");
			$('.btn_save').live('click',function(){
				if( confirm('更新してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});
			
			$('.btn_sort').live('click',function(){
					document.fm.mode.value = 'sort';
					document.fm.submit();
			});
			
			$('#btn_map_modify').live('click',function(){
				//document.fm.map_no.value = 'sort';
				location.href = "mmapg_form.php?id=" + document.fm.map_no.value + "&week_cd={{ $forms.matrix_cd }}" ;
			});

			
			$('a.tddel').live('click',function(){
				$('#rtr_' + $(this).attr("id") ).remove();
				$(this).closest('tr').remove();
			});
			$('.chkdum').live('click',function(){
				var index =  $('#fm [name^=cdummy]').index($(this));
				if  ( $(this).attr("checked") ) {
					$('#fm [name^=dummy]').eq(index).attr("value", "1");
				}else {
					$('#fm [name^=dummy]').eq(index).attr("value", "");
				}
				
			});
			$('.cmark').live('click',function(){
				var index =  $('#fm [name^=cmark]').index($(this));
				if  ( $(this).attr("checked") ) {
					$('#fm [name^=mark]').eq(index).attr("value", "1");
				}else {
					$('#fm [name^=mark]').eq(index).attr("value", "");
				}
			});
		});
		
		function add_tr(scd, snm,smx ,flg) {
				var strTd = $("#zzz_tab_r tr").eq(0).html();
				var service = "0";
				var dispservice = "　";
				if (flg == '1') {
					dispservice = "サービス";
					service = "1";
				}
				var regSerDisp = new RegExp("zzz_service_disp","gi");
				strTd = strTd.replace(regSerDisp, dispservice);
				
				var regSer = new RegExp("zzz_service","gi");
				strTd = strTd.replace(regSer, service);
				
				$('#1_tab_r' ).append('<tr  id="rtr_' + scd +  '" >' + strTd +'</tr>');
				
				var strHtml = $("#zzz_tab_l tr").eq(0).html();
				
				 var regCD = new RegExp("zzz_shop_cd","gi");
				 strHtml = strHtml.replace(regCD, scd);
				 
				 var regNM = new RegExp("zzz_shop_name","gi");
				 strHtml = strHtml.replace(regNM, snm);
				$('#1_tab_l' ).append('<tr>' + strHtml +'</tr>');
		}
		
		//-------------------------search -----------------
		g_shop_ul_to_grid = true;
		function copy_shop_pop_ul_to_grid() {
			var cdsul   = document.getElementsByName( 'shop_cd_ul[]');
			var namesul = document.getElementsByName('shop_name_ul[]');
			var cdarr   = new Array();
			$.each(cdsul, function(i,val){
				cdarr[i] = val.value;
			}); 
			
			if (gMutiObj=="map_shop") {
				$.each(namesul, function(i,val){
					add_tr(cdarr[i], val.value, '','0');
					setmaxSeq();
				}); 
				
			} else {
				$.each(namesul, function(i,val){
					add_tr(cdarr[i], val.value, '　','1')
					setmaxSeq();
				}); 
			}
		}
		function li_a_map(inID, inVal,inSmx) {
			if (checkMapShopNames(inID)) {
				var strHtml = "<li id='a" + inID +"' class='item_li'> <a href='#'  style='color:red' class='li_del' >X</a>&nbsp;&nbsp;"+ inID + "&nbsp;&nbsp;" + inVal;
				strHtml = strHtml + "<input type='hidden' value='" + inID + "'  name ='shop_cd_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inVal + "' name ='shop_name_ul[]'>";
				//strHtml = strHtml + "<input type='hidden' value='" + inSmx + "' name ='shop_smx_ul[]'>";
				strHtml = strHtml + "</li>";
				$("#pop_ul").append(strHtml);
			} 
		}
		function setmaxSeq() {
			var seqs = document.getElementsByName('seq[]');
			var maxno = 1;
			var index = 0;
			$.each(seqs, function(i,val){
				var nowseq = getNum(val.value);
				if (maxno * 1 <= nowseq ) {
					maxno = nowseq + 1;
				} 
				 index = i ;
			}); 
			if (index>0) {
				index = index - 1 ;
			}
			$('#fm [name^=seq]').eq(index).attr("value", maxno);
			
		}
		function getNum(s){
		    if (s!=null && s!="")
		    {
		        if (isNaN(s)){
		        	return 0;
		        } else {
		        	return s*1;
		        }
		    }
		    return 0;
		}

		function checkMapShopNames(inval) {
			var retFlg = true;
			var names = document.getElementsByName('shop_cd[]');
			//$.each($("input:hidden"), function(i,val){
			$.each(names, function(i,val){
				if (inval == val.value) {
			   	 retFlg = false;
			   	 alert("既に選択された項目です");
			   	 return false;
			   	}
			}); 
				
			
			var namesul = document.getElementsByName('shop_cd_ul[]');
			$.each(namesul, function(i,val){
			     if (inval == val.value) {
			    	 retFlg = false;
			    	 alert("既に選択された項目です");
			    	 return false;
			     	}
			}); 
			return retFlg;
		}

		function moveUp(obj){
		    var current=$(obj).parent().parent();
		    var prev=current.prev();
		    if(current.index()>1)
		    {
		        current.insertBefore(prev);
		    }
		}
		
		function moveDown(obj){
		    var current=$(obj).parent().parent();
		    var next=current.next();
		    if(next)
		    {
		        current.insertAfter(next);
		    }
		}
		//--------------------------------------------------------------------------
		//fun(2012 );
		</script>
		
	</head>
<body id="">
{{ $menu }}
{{ $logout }}
		<div id="container"><div class="wrapper">
			<h2>マップグループマスター管理</h2>
			<ul class="submenu clearfix">
				<li><a href="mmapg_index.php">マップグループ情報一覧</a></li>
				<li>マップグループ情報更新</li>
				{{if !$isG7 }}<li><a href="mmapshop_import.php">CSV更新</a></li>{{ /if }}
				<li><a href="mmservice_index.php">サービスマップマスタ</a></li>
			</ul>
			<h3>マップグループ情報更新{{ if $phase == 'complete' }}完了{{ /if }}</h3>
{{ if $phase == 'input' }}
			<p class="message">内容を入力し、更新してください</p>
<!--  
<p>■{{ $forms.year4 }}年度 &nbsp;  第{{ $forms.week_cd }}周&nbsp; {{ if $forms.week_seq != '0'  }}  第{{ $forms.week_seq }}回&nbsp;  {{ /if }} {{ $forms.flier_date }}</p>
-->
<form name="fm" id = "fm" action="mmapshop_form.php" method="post">
<p>	
	<b>マップNO : {{ $forms.map_no }}&nbsp;&nbsp;区分 : {{ $forms.sort }}{{ if $forms.media_name != '' }}  &nbsp;&nbsp;新聞紙名: {{ $forms.media_name }} {{ /if }} &nbsp;&nbsp; &nbsp; &nbsp;
	{{ $forms.year4 }}年度 &nbsp; &nbsp; {{ $forms.week_cd }}週目 {{ if $forms.week_seq  }}  &nbsp; {{ $forms.week_seq }}回{{ /if }}&nbsp;&nbsp;
	最終更新日時 :{{ $forms.u_time|date_format:"%Y/%m/%d %H:%M" }}</b>
	<input type="hidden" name="map_no"     value="{{ $forms.map_no }}" /><input type="hidden" name="sort" value="{{ $forms.sort }}" />
	<input type="hidden" name="media_name" value="{{ $forms.media_name }}" /><input type="hidden" name="matrix_cd" value="{{ $forms.matrix_cd }}" />
	<input type="hidden" name="week_cd"    value="{{ $forms.week_cd }}" />
	<input type="hidden" name="year4"      value="{{ $forms.year4 }}" />
	<input type="hidden" name="week_seq"   value="{{ $forms.week_seq}}" />
	<input type="hidden" name="u_time"     value="{{ $forms.u_time }}" />
	<div class="errmsg"> {{ $errmsg|escape }} </div>
</p>
<p>
	&nbsp;&nbsp;<button type="button"  id="map_shop" class="btn_search_muti"  class="submit"><span>店舗追加</span></button>
	&nbsp;&nbsp;<button type="button"  id="service"  class="btn_search_muti" ><span>サービス追加</span></button>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	&nbsp;&nbsp;<button type="button"  id="btn_map_modify"  class="button" ><span>マップ区分変更</span></button>
</p>
 <div class="l_div"> 
 <table class="formTable" id = "1_tab_l" style="table-layout:fixed;word-wrap:break-word;word-break;break-all;" >
 <tr><th style="width:42px"><span style="width:42px">更新</span></th><th style="width:50px"><span >店舗<br>コード</span></th>
 <th><span >店名</span></th>
 </tr>
 {{ foreach from=$forms.d key=kk item=vv name="member" }}
  <tr><td><a href='#'  style='color:red' class='tddel' id = '{{ $vv.shop_cd }}' >[削除]</a><input type="hidden" name="id[]" value="{{ $vv.id }}" /> </td>
	<td><input type="text"  name="shop_cd[]" class="dtext" value="{{ $vv.shop_cd }}" readonly/></td>
	<td><input type="text"  name="shop_name[]"   class="dtext" value="{{ $vv.shop_name }}" readonly/></td>
	<!-- <td><input type="text"  name="shop_smx[]"    class="dtext" value="{{ if $vv.smx == '1' or $vv.smx == '○' }}○{{ /if }}" readonly/></td>--></tr> 
{{ /foreach }}
 </table>
 </div>
<div class="r_div"> 
	<table class="formTable" id = "1_tab_r"  style="width:950px" ><tr>
		<th ><span>順番</span></th>
		<th><span>合同<br>マップ </span></th>
		<th><span>合同折込</span></th>
		<th style="width:100px;" ><span >グループNO<br>(親店舗)</span></th>
		<th style="width:50px;" ><span >親</span></th>
		<th><span>折込負担<br>比率</span></th>
		<th><span>ダミー</span></th>
		<th><span>サービス</span></th>
		<th><span>コメント</span></th>
		<th><span >備　考</span></th>
	</tr>
{{ foreach from=$forms.d key=kk item=vv name="member" }}
	<tr id="rtr_{{ $vv.shop_cd}}" >
	<td> <input type="text" name="seq[]" class="text"  value="{{ $vv.seq|escape }}"style="width:50px" /></td>
 	<td>{{ html_options name='congruent_map[]' options=$congruent selected=$vv.congruent_map   }}</td>
	<td >{{ html_options name='congruent_ins[]' options=$congruent_ins selected=$vv.congruent_ins  }}</td>
	<td> <input type="text" name="group_no[]" class="text" style="width:80px" value="{{ $vv.group_no|escape }}" /></td>
	<td><input  name="cmark[]" type="checkbox" class="cmark" value="1" {{ if $vv.mark == 1}}checked{{ /if  }} />  
	 <input type="hidden" name="mark[]" value="{{$vv.mark}}"/></td>
	 
	<td> <input type="text" name="ins_load_ratio[]" class="text" style="width:100px" value="{{ $vv.ins_load_ratio|escape }}" /></td>
	<td align="center"> <input type="checkbox" name="cdummy[]" class="chkdum" value="1" {{ if $vv.dummy == 1}}checked{{ /if  }}/>
	<input type="hidden" name="dummy[]" value="{{ $vv.dummy }}"/> </td>
	<td> <input type="text" name="servicedip[]" class="dtext" style="width:60px" value="{{ if $vv.service == 1}} サービス {{ /if  }}" readonly/> <input type="hidden" name="service[]" value="{{ $vv.service }}"/></td>
	<td> <input type="text" name="comm[]" class="text" value="{{ $vv.comm|escape }}" /> </td>
	<td> <input type="text" name="memo[]" class="text" value="{{ $vv.memo|escape }}" /></td>
	</tr>
{{ /foreach }}
	</table>
</div>
<div class = "all_div">
	<p  class="button" >
		<button type="button" class="btn_sort"  class="submit btnleft"><span>順番変更</span></button> &nbsp;&nbsp;
		<button type="button" class="btn_save"  class="submit btnleft"><span>更新</span></button>
	</p>
				<input type="hidden" name="mode" value="" />
</div>
</form>
<div id = "divlibase" style="display:none">
 <table class="formTable" id = "zzz_tab_l" >
  <tr><td><a href='#'  style='color:red' class='tddel' id = 'zzz_shop_cd' >[削除]</a><input type="hidden" name="id[]" value="" /> </td>
	<td><input name="shop_cd[]"  type="text"   style="width:45px" class="dtext" value="zzz_shop_cd" readonly/></td>
	<td><input type="text" name="shop_name[]"  style="width:90%" class="dtext" value="zzz_shop_name" readonly/></td>
	<!--  <td><input type="text" name="shop_smx[]"  style="width:30px"   class="dtext" value="zzz_smx" readonly/></td>--></tr>
 </table>
	<table class="formTable" id = "zzz_tab_r" >
	<tr id="rtr_{{ $vv.shop_cd}}" >
	<td> <input type="text" name="seq[]" class="text"  style="width:50px"  value="0" /></td>
	<td>{{ html_options name='congruent_map[]' options=$congruent selected=0  }}</td>
	<td>{{ html_options name='congruent_ins[]' options=$congruent_ins selected=0  }}</td>
	<td> <input type="text" name="group_no[]" class="text" style="width:100px" value="" /></td>
	<td><input  name="cmark[]" type="checkbox" class="cmark" value="1"></input> <input type="hidden" name="mark[]" value=""/> </td>
	<td> <input type="text" name="ins_load_ratio[]" class="text" style="width:100px" value="" /></td>
	<td align="center"> <input type="checkbox" name="cdummy[]" class="chkdum" value="1" /> <input type="hidden" name="dummy[]" value=""/></td>
	<td> <input type="text" name="servicedip[]" class="dtext" style="width:60px" value="zzz_service_disp" readonly/> <input type="hidden" name="service[]" value="zzz_service"/></td>
	<td> <input type="text" name="comm[]" class="text" value="" /> </td>
	<td> <input type="text" name="memo[]" class="text" value="" /></td>
	</tr>
	</table>
</div>	

 <div id="dialogmuti" >
</div>

 
{{ /if }}

{{ if $phase == 'complete' }}
	<p class="message">{{ $message }}</p>
	<ul>
		<li>>> <a href="mmapshop_index.php?hist=2">一覧ページに戻る</a></li>
		<li>>> <a href="mmapshop_form.php?mm={{ $forms.map_no }}&ww={{ $forms.matrix_cd }}">更新</a></li>
	</ul>
{{ /if }}
		
		</div>
		</div>

<div class = "all_div" >{{ $footer }}</div>
	</body>
</html>